import React, { useContext } from "react";
import { deleteNote } from "../request/api";
import Trash from "../icons/Trash";
import { NoteContext } from "../context";
function DeleteButton({ noteId }) {
  const { setNotes } = useContext(NoteContext);
  const handleDelete = () => {
    setNotes((prevNotes) => prevNotes.filter((note) => note._id !== noteId));
    try {
      deleteNote(noteId);
    } catch (error) {
      console.error(error);
    }
  };

  return (
    <div onClick={handleDelete}>
      <Trash />
    </div>
  );
}
export default DeleteButton;
